# 测试HTTPS内网地址的微信推送功能
# 这个脚本用于验证SSL证书验证跳过配置是否生效

Write-Host "开始测试HTTPS内网地址的微信推送功能..." -ForegroundColor Green

# 测试参数
$baseUrl = "http://localhost:5000"
$testEndpoint = "$baseUrl/api/WeChatNotification/send-refund-submitted"

# 构建测试请求体
$requestBody = @{
    patientId = "1410007308"
    refundId = 999
}
$requestBodyJson = $requestBody | ConvertTo-Json

Write-Host "请求地址: $testEndpoint" -ForegroundColor Yellow
Write-Host "请求体: $requestBodyJson" -ForegroundColor Yellow

try {
    # 发送POST请求
    $response = Invoke-RestMethod -Uri $testEndpoint -Method POST -Body $requestBodyJson -ContentType "application/json" -TimeoutSec 30
    
    Write-Host "\n=== 测试结果 ===" -ForegroundColor Green
    Write-Host "请求成功!" -ForegroundColor Green
    Write-Host "响应内容:" -ForegroundColor Yellow
    $response | ConvertTo-Json -Depth 10 | Write-Host
    
    if ($response.success -eq $true) {
        Write-Host "\n✅ 微信推送功能测试成功!" -ForegroundColor Green
        Write-Host "✅ HTTPS内网地址SSL证书验证跳过配置生效!" -ForegroundColor Green
    } else {
        Write-Host "\n⚠️  微信推送功能返回失败状态" -ForegroundColor Yellow
        Write-Host "错误信息: $($response.message)" -ForegroundColor Red
    }
}
catch {
    Write-Host "\n=== 测试失败 ===" -ForegroundColor Red
    Write-Host "错误信息: $($_.Exception.Message)" -ForegroundColor Red
    
    if ($_.Exception.Message -like "*SSL*" -or $_.Exception.Message -like "*certificate*" -or $_.Exception.Message -like "*TLS*") {
        Write-Host "\n❌ 检测到SSL/TLS相关错误，可能需要进一步配置" -ForegroundColor Red
    }
}

Write-Host "\n测试完成。" -ForegroundColor Cyan
Write-Host "\n注意事项:" -ForegroundColor Yellow
Write-Host "1. 确保appsettings.WeChat.json中的ApiUrl配置为: https://10.1.221.5:8011" -ForegroundColor White
Write-Host "2. 如果仍有SSL错误，可能需要在服务器上安装相应的证书" -ForegroundColor White
Write-Host "3. 当前配置已跳过SSL证书验证，适用于内网环境" -ForegroundColor White